const { spawn } = require('child_process');
const path = require('path');

console.log('Starting fushen project...');

// 启动后端服务器
const backend = spawn('node', ['server/server-simple.js'], {
  cwd: __dirname
});

backend.stdout.on('data', (data) => {
  console.log(`[Backend] ${data}`);
});

backend.stderr.on('data', (data) => {
  console.error(`[Backend Error] ${data}`);
});

backend.on('close', (code) => {
  console.log(`[Backend] Process exited with code ${code}`);
});

// 启动前端开发服务器
const frontend = spawn('npm', ['run', 'dev'], {
  cwd: __dirname,
  shell: true
});

frontend.stdout.on('data', (data) => {
  console.log(`[Frontend] ${data}`);
});

frontend.stderr.on('data', (data) => {
  console.error(`[Frontend Error] ${data}`);
});

frontend.on('close', (code) => {
  console.log(`[Frontend] Process exited with code ${code}`);
});

// 处理退出信号
process.on('SIGINT', () => {
  console.log('Shutting down...');
  backend.kill();
  frontend.kill();
  process.exit(0);
});

console.log('Project started successfully!');
console.log('Frontend: http://localhost:5173');
console.log('Backend: http://localhost:3000');